import DefaultCanvas from "../../DefaultCanvas";
import ICanvas from "../../ICanvas";
import Time from "../../Time";
import IHooksRender from "../IHooksRender";


export default class RenderFrameDetails implements IHooksRender{
    canRender(): boolean {
        return true;
    }

    beforeRender(canvas: ICanvas) {
        
    }
    


    afterRender(canvas: ICanvas) {
        let defaultCanvas = canvas as DefaultCanvas
        this.renderFrames(defaultCanvas)
    }

    renderFrames(canvas:DefaultCanvas){
        let ctx = canvas.ctx
        try{
            ctx.save()
            ctx.beginPath()
            ctx.fillStyle = "gray"
            ctx.rect(canvas.canvasEl.width-200,10,200,200)
            ctx.fill()
            ctx.fillStyle = "black"
            ctx.textBaseline = 'middle'
            let fixedFrameTime = (Time.frameTime*1000).toFixed(2)
            let fixedFps = (1/Time.frameTime).toFixed(0)
            ctx.fillText("frameTime: "+fixedFrameTime+ " ms",canvas.canvasEl.width-200+20,30)
            ctx.fillText("fps: "+fixedFps,canvas.canvasEl.width-200+20,50)
            
        }catch(e){
            console.log(e);
        }finally{
            ctx.restore()   
            ctx.closePath()
        }
    }
}